
package ch.hearc.meteo.imp.afficheur.real;

import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JPanel;

import ch.hearc.meteo.imp.afficheur.real.moo.StationMeteoElement;
import ch.hearc.meteo.imp.afficheur.real.vue.JPanelInformationsMeteo;
import ch.hearc.meteo.imp.afficheur.real.vue.JPanelLeft;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelStationMeteoControlLocal;
import ch.hearc.meteo.spec.reseau.MeteoServiceWrapper_I;
import ch.hearc.meteo.tools.ImageShop;

public class JFrameStationMeteoLocal extends JFrameStationMeteo
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	private JFrameStationMeteoLocal()
		{
		super();
		JDialogPreferencesLocal preferences = new JDialogPreferencesLocal();
		if (preferences.isOk() == false)
			{
			System.exit(0);
			}
		this.isLocal = true;

		geometry();
		control();
		apparence();

		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	public static JFrameStationMeteo getInstance()
		{
		if (instance == null)
			{
			instance = new JFrameStationMeteoLocal();
			}

		return instance;
		}

	@Override
	public void refreshSelectedStations(StationMeteoElement stationMeteoElement)
		{
		this.panelInformationsMeteo.updatelisteStationMeteoSelectionnee(stationMeteoElement);
		this.panelStationMeteoControlLocal.refresh();
		}

	@Override
	public void addMeteoServiceWrapper(MeteoServiceWrapper_I meteoServiceWrapper_I, AfficheurService afficheurService)
		{
		panelLeft.addStationMeteo(afficheurService.getStationMeteoElement().getPanelStationMeteoListElement());

		}

	@Override
	public void removeMeteoServiceWrapper(MeteoServiceWrapper_I meteoServiceWrapper_I, AfficheurService afficheurService)
		{
		panelLeft.removeStationMeteo(afficheurService.getStationMeteoElement().getPanelStationMeteoListElement());
		panelInformationsMeteo.removeStationMeteoSelectionnee(afficheurService.getStationMeteoElement());
		}

	/*------------------------------*\
	|*				Set				*|
	\*------------------------------*/

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/

	@Override
	public JPanelInformationsMeteo getPanelInformationsMeteo()
		{
		return panelInformationsMeteo;
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private void geometry()
		{
		BorderLayout layout = new BorderLayout();

		this.setLayout(layout);
		panelInformationsMeteo = new JPanelInformationsMeteo();

		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		panelLeft = new JPanelLeft();
		panelStationMeteoControlLocal = new JPanelStationMeteoControlLocal(panelInformationsMeteo.getListeStationsMeteoSelectionnee());
		panel.add(panelLeft, BorderLayout.CENTER);
		panel.add(panelStationMeteoControlLocal, BorderLayout.NORTH);

		this.add(panelInformationsMeteo, BorderLayout.CENTER);
		this.add(panel, BorderLayout.WEST);

		}

	private void control()
		{
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.addWindowListener(new WindowListener()
			{

				@Override
				public void windowOpened(WindowEvent arg0)
					{
					// TODO Auto-generated method stub

					}

				@Override
				public void windowIconified(WindowEvent arg0)
					{
					// TODO Auto-generated method stub

					}

				@Override
				public void windowDeiconified(WindowEvent arg0)
					{
					// TODO Auto-generated method stub

					}

				@Override
				public void windowDeactivated(WindowEvent arg0)
					{
					// TODO Auto-generated method stub

					}

				@Override
				public void windowClosing(WindowEvent arg0)
					{
					panelLeft.removeAllStationsMeteo();
					}

				@Override
				public void windowClosed(WindowEvent arg0)
					{

					}

				@Override
				public void windowActivated(WindowEvent arg0)
					{
					// TODO Auto-generated method stub

					}
			});
		}

	private void apparence()
		{
		this.setExtendedState(MAXIMIZED_BOTH);
		this.setIconImage(ImageShop.ICON_LOCAL);
		this.setTitle("Station météo");
		this.setVisible(true);

		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	private JPanelInformationsMeteo panelInformationsMeteo;

	private JPanelStationMeteoControlLocal panelStationMeteoControlLocal;

	}
